#include "Bank.h"
#include "AccountFactory.h"
#include <iostream>
#include <assert.h>


using namespace std;

Account* randomAccount(){
	int rnd =  rand() % 3;
	Account* retVal;
	switch (rnd) 
	{
	case 0:
		retVal = new Account(AccountFactory::CreateAccount(string("TwoYearAccount")));
		break;
	case 1:
		retVal = new Account(AccountFactory::CreateAccount(string("FamilyAccount")));
		break;
	case 2:
		retVal = new Account(AccountFactory::CreateAccount(string("StockAccount")));
		break;
	default:
		return 0;
	}			
	rnd = rand() % 3;
	switch (rnd) 
	{
	case 0:
		retVal->setSavingPeriod(3);
		break;
	case 1:
		retVal->setSavingPeriod(5);
		break;
	case 2:
		retVal->setSavingPeriod(10);
		break;
	}
	struct tm t;
	t.tm_year = 105 + (rand() % 5);
	t.tm_mon = 0;
	t.tm_mday = 0;
	t.tm_hour = 0;
	t.tm_min = 0;
	t.tm_sec = 0;
	t.tm_isdst = -1;
	retVal->setOpenDate(t);

	return retVal;
}

int main(int argc, char* argv[]) 
{
	srand(time(0));

	Bank* inst = Bank::getInstance();
	assert(inst == Bank::getInstance());

	list<Account*> acctList;
	for (int i=0; i < 10; i++){
		Account* tempAcct = randomAccount();
		acctList.push_back(tempAcct);
		inst->attach(tempAcct);
		cout << "Account #" << i << " is of type " << (tempAcct->getType() == BankObserver::stock ? "StockAccount" : (tempAcct->getType() == BankObserver::family ? "FamilyAccount" : "TwoYearAccount")) << ".  Saving period: " << tempAcct->getSavingPeriod() << " years, open year: " << tempAcct->getOpenDate().tm_year + 1900 << endl;
	}	
	cout << endl;
	inst->notifyGiveBonus();
	inst->notifyInvestStock();
	inst->notifyMeetingClerk();

	for (list<Account*>::iterator iter = acctList.begin(); iter != acctList.end(); iter++){
		inst->detach(*iter);
	}

	inst->notifyGiveBonus();
	inst->notifyInvestStock();
	inst->notifyMeetingClerk();

	return 0;
}